<!--#
layout("/layouts/platform.html"){
#-->
<style>
    .el-upload input[type=file] {
        display: none;
    }

    .el-upload__text {
        color: #606266;
        font-size: 14px;
        text-align: center;
    }
</style>
<div id="app"  v-cloak>
    <el-row class="header navbar bg-white">
        <div class="btn-group tool-button" style="line-height: 50px;">
            设备编号：<el-input placeholder="设备编号" v-trim v-model="pageForm.code" size="mini" style="width:180px;" clearable></el-input>
            设备名称：<el-input placeholder="设备名称" v-trim v-model="pageForm.name" size="mini" style="width:180px;" clearable></el-input>
            设备状态：<el-cascader placeholder="设备状态" v-trim v-model="pageForm.status" size="mini" :options="allMap.statusOptions" clearable style="width:180px;"></el-cascader>
            <el-button slot="append" icon="el-icon-search" size="mini" @click="doSearch" circle></el-button>
            <el-button  size="mini" @click="getSelect" >高级搜索</el-button>

        </div>
        <div class="pull-right offscreen-right" style="margin-right: 20px;line-height: 50px;">
            <el-row>
                <el-tooltip class="item" effect="dark" content="导出EXCEL" placement="top">
                    <el-button circle icon="el-icon-download" size="mini" @click="createExport"/>
                </el-tooltip>
            </el-row>
        </div>
    </el-row>

    <el-row class="el-table-container">
        <el-table :data="tableData" @sort-change='pageOrder' height="520"  border size="small" header-align="center"  style="width: 100%" @selection-change="handleSelectionChange">

            <el-table-column fixed="left" sortable="custom" prop="code" label="设备编号" width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column fixed="left" sortable="custom" prop="name" label="设备名称" width="200px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="status" label="设备状态" min-width="120px;" header-align="center" align="center" show-overflow-tooltip>
                <template slot-scope="scope" >{{getDict(scope.row.status,allMap.statusMap)}}</template>
            </el-table-column>
            <el-table-column sortable="custom" prop="model" label="规格型号" width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="detectionrange" label="检测范围" width="220px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="accuracy" label="精度要求" width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="factorycode" label="出厂编号" width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="number" label="数量（台/套）" min-width="130px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="company" label="制造厂商" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="purchaseprice" label="购置价格（元）" min-width="130px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="purchasedate" label="购置日期" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="calculate" label="溯源方式" min-width="120px;" header-align="center" align="center" show-overflow-tooltip>
                <template slot-scope="scope" >{{getDict(scope.row.calculate,allMap.calculateMap)}}</template>
            </el-table-column>
            <el-table-column sortable="custom" prop="calculateunit" label="溯源单位" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="calculatecycle" label="溯源周期" min-width="120px;" header-align="center" align="center" show-overflow-tooltip>
                <template slot-scope="scope" >{{scope.row.calculatecycle}}{{getDict(scope.row.calculatecycletype,allMap.calculateCycleTypeMap)}}</template>
            </el-table-column>
            <el-table-column sortable="custom" prop="calculatedate" label="下次溯源日期" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="reportcode" label="证书编号" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="depositadress" label="存放地点" min-width="220px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column  prop="managername" label="设备责任人" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column  prop="applyname" label="使用部门" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="classification" label="分类情况" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="importedflag" label="是否进口设备" min-width="120px;" header-align="center" align="center" show-overflow-tooltip>
                <template slot-scope="scope" >
                    <span v-if="scope.row.importedflag==0">是</span>
                    <span v-else>否</span>
                </template>
            </el-table-column>
            <el-table-column sortable="custom" prop="assetcode" label="资产编号" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="supplyphone" label="供货商联系电话" min-width="150px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column  prop="remark" label="备注" min-width="320px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>

        </el-table>
    </el-row>
    <el-row class="el-pagination-container">
        <el-pagination @size-change="pageSizeChange" @current-change="pageNumberChange" :current-page="pageForm.pageNumber" :page-sizes="[10, 20, 30, 50]"
                       :page-size="pageForm.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pageForm.totalCount">
        </el-pagination>
    </el-row>
    <el-drawer title="高级搜索" :visible.sync="selectDrawer" direction="rtl" :before-close="closeSelect" size="85%">
        <div  style="padding-left: 20px;height: calc(100vh - 37px);overflow-y: auto;overflow-x: hidden">
            <!--<el-transfer filterable  :filter-method="filterMethod" :titles="['待选择条件', '已选择条件']" :button-texts="['取消', '选择']"
            filter-placeholder="请输入信息项" v-trim v-model="selectValue" :data="allMap.listSelect"> </el-transfer>-->
            <el-form  size="mini" label-width="130px" >
                <el-row :gutter="20">
                    <el-col :span="8" v-for="select in allMap.listSelect">
                        <el-form-item :prop="select.key" :label="select.label" v-if="select.condition=='drop'">
                            <el-cascader clearable v-trim v-model="select.value" :options="select.options"  style="width:180px;"></el-cascader>
                        </el-form-item>
                        <el-form-item :prop="select.key" :label="select.label" v-if="select.condition=='like'">
                            <el-input maxlength="30"  v-trim v-model="select.value"  style="width:180px;"></el-input>
                        </el-form-item>
                        <el-form-item :prop="select.key" :label="select.label" v-if="select.condition=='number'">
                            <el-input-number maxlength="30"  v-trim v-model="select.value"  style="width:180px;"></el-input-number>
                        </el-form-item>
                        <el-form-item :prop="select.key" :label="select.label" v-if="select.condition=='date'">
                            <el-date-picker type="date" placeholder="开始日期" v-trim v-model="select.startDate" size="mini" value-format="yyyy-MM-dd" style="width: 130px;"></el-date-picker>
                            -<el-date-picker type="date" placeholder="结束日期" v-trim v-model="select.endDate" size="mini" value-format="yyyy-MM-dd" style="width: 130px;"></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col>
                        <el-button  @click="selectDrawer = false" plain>返回</el-button>
                        <el-button type="primary" @click="doSearch" plain>搜索</el-button>
                        <el-button type="info" @click="doClear" plain>清空</el-button>
                    </el-col>
                </el-row>
            </el-form>
        </div>
    </el-drawer>
</div>
<style scoped>
    .el-table--border th.gutter:last-of-type {
        display: block !important;
        width: 17px !important;
    }

</style>
<script>
    var allMap = {statusMap:${statusMap},statusOptions:${statusOptions},calculateMap:${calculateMap},calculateCycleTypeMap:${calculateCycleTypeMap},listSelect:${listSelect}}
    new Vue({
        el: "#app",
        data: function () {
            return {
                allMap:allMap,
                tableData: [],
                addDialogVisible:false,
                pageForm: {},
                selectDrawer: false,
            }
        },
        methods: {
            pageOrder: function (column) {//按字段排序
                this.pageForm.pageOrderName = column.prop;
                this.pageForm.pageOrderBy = column.order;
                this.pageData();
            },
            pageNumberChange: function (val) {//页码更新操作
                this.pageForm.pageNumber = val;
                this.pageData();
            },
            pageSizeChange: function (val) {//分页大小更新操作
                this.pageForm.pageSize = val;
                this.pageData();
            },
            pageData: function () {//加载分页数据
                var self = this;
                self.pageForm.listSelect= [];
                for(const select of self.allMap.listSelect){
                    if(select.value || select.startDate ||select.endDate){
                        self.pageForm.listSelect.push(select);
                    }
                }
                self.pageForm.listSelect=JSON.stringify(self.pageForm.listSelect)
                if(nONull(self.pageForm.status)){self.pageForm.status = self.pageForm.status.join(",");}
                sublime.showLoadingbar();//显示loading
                $.post(base + "/platform/bus/reports/equipment/data", self.pageForm, function (data) {
                    sublime.closeLoadingbar();//关闭loading
                    if (data.code == 0) {
                        self.tableData = data.data.list;
                        self.pageForm.totalCount = data.data.totalCount;
                        if(nONull(self.pageForm.status)){self.pageForm.status = self.pageForm.status.split(",");}
                        self.closeSelect();
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            doSearch: function () {
                this.pageForm.pageNumber = 1;
                this.pageData();
            },
            doClear:function(){
                this.allMap.listSelect.forEach((item,index)=>{
                    if(item.condition=='drop'){
                        item.value=[];
                    }else if(item.condition=='like'||item.condition=='number'){
                        item.value="";
                    }else{
                        item.startDate = "";
                        item.endDate = "";
                    }
                })
                this.allMap.listSelect=JSON.parse(JSON.stringify(this.allMap.listSelect));
            },
            getSelect(){
                this.selectDrawer = true
            },
            closeSelect(){
                this.selectDrawer = false
            },
            dropdownCommand: function (command) {//监听下拉框事件
                var self = this;
                if("edit" == command.type){//修改
                    //根据id获取数据
                    $.post(base + "/platform/bus/equipment/detail/" + command.row.id, {}, function (data) {
                        if (data.code == 0) {
                            self.formData =  data.data;
                            if(nONull(self.formData.status)){self.formData.status = self.formData.status.split(",");}
                            if(nONull(self.formData.calculate)){self.formData.calculate = self.formData.calculate.split(",");}
                            if(nONull(self.formData.calculateCycleType)){self.formData.calculateCycleType = self.formData.calculateCycleType.split(",");}
                            if(nONull(self.formData.managerBy)){self.formData.managerBy = self.formData.managerBy.split(",");}
                            if(nONull(self.formData.applyDept)){self.formData.applyDept = self.formData.applyDept.split (",");}
                        } else {
                            self.$message({message: data.msg,type: 'error'});
                        }
                    }, "json");
                    //打开窗口
                    this.addDialogVisible=true;
                }
            },
            getDict: function (val,map) {
                if (val!= null && val!=undefined &&val!="" &&val!="null" &&val!="undefined" && map!=null && map !=undefined){
                    var str = val.split(",");
                    var strname="";
                    for (var a=0;a<str.length;a++){
                        strname+=map[str[a]];
                        if(strname == null){
                            alert(1)
                        }
                        if(a<(str.length-1)){
                            strname+="/";
                        }
                    }
                    return strname;
                }
                return "";
            },
            handleSelectionChange: function (val) {
                this.multipleSelection = val;
            }
            ,
            createExport(){
                var self = this;
                var url = base + "/platform/bus/reports/equipment/export";
                var form = document.createElement("form");
                form.style.display = 'none';
                form.action = url;
                form.method = "post";
                document.body.appendChild(form);

                if(nONull(self.pageForm.code)){
                    var code = document.createElement("input");
                    code.type = "hidden";
                    code.name = "code";
                    code.value = self.pageForm.code;
                    form.appendChild(code);
                }
                if(nONull(self.pageForm.name)) {
                    var name = document.createElement("input");
                    name.type = "hidden";
                    name.name = "name";
                    name.value = self.pageForm.name;
                    form.appendChild(name);
                }
                if(nONull(self.pageForm.status)) {
                    var status = document.createElement("input");
                    status.type = "hidden";
                    status.name = "status";
                    status.value = self.pageForm.status;
                    form.appendChild(status);
                }
                if(nONull(self.pageForm.listSelect)) {
                    var listSelect = document.createElement("input");
                    listSelect.type = "hidden";
                    listSelect.name = "listSelect";
                    listSelect.value = self.pageForm.listSelect;
                    form.appendChild(listSelect);
                }
                if(nONull(self.pageForm.pageOrderName)) {
                    var pageOrderName = document.createElement("input");
                    pageOrderName.type = "hidden";
                    pageOrderName.name = "pageOrderName";
                    pageOrderName.value = self.pageForm.pageOrderName;
                    form.appendChild(pageOrderName);
                }
                if(nONull(self.pageForm.pageOrderBy)) {
                    var pageOrderBy = document.createElement("input");
                    pageOrderBy.type = "hidden";
                    pageOrderBy.name = "pageOrderBy";
                    pageOrderBy.value = self.pageForm.pageOrderBy;
                    form.appendChild(pageOrderBy);
                }
                form.submit();
                form.remove();
            }
        },
        created: function () {
            this.doSearch();
        }
    });

    function nONull(val){
        if (val!= null && val!=undefined &&val!="" &&val!="null" &&val!="undefined" ){
            return true;
        }else{
            return false;
        }
    }
</script>
<!--#
}
#-->
